import { Controller, Post, Body } from '@nestjs/common';
import { UserService } from './user.service';
import { CreateUserDto } from './dto/create-user.dto';
import { UserItem, UserItemResponse } from './vo/user.vo';
import { ApiBody, ApiOkResponse, ApiOperation, ApiTags } from '@nestjs/swagger';
import { LoginDto } from './dto/login.dto';
import { LoginResponse } from './vo/login.vo';

@ApiTags('用户')
@Controller('user')
export class UserController {
  constructor(private readonly userService: UserService) {}

  @ApiOperation({ summary: '用户注册' })
  @ApiBody({
    type: CreateUserDto,
  })
  @ApiOkResponse({ description: '注册成功', type: UserItemResponse })
  @Post('register')
  create(@Body() createUserDto: CreateUserDto): Promise<UserItem> {
    return this.userService.create(createUserDto);
  }

  @ApiOperation({ summary: '用户登录' })
  @ApiBody({
    type: LoginDto,
  })
  @ApiOkResponse({ description: '登录成功', type: LoginResponse })
  @Post('login')
  login(@Body() loginDto: LoginDto): Promise<string> {
    return this.userService.login(loginDto);
  }
}
